package cn.huolabao.controller;

import cn.huolabao.common.core.utils.R;
import cn.huolabao.model.SysDept;
import cn.huolabao.service.SysDeptService;
import cn.huolabao.vo.portal.PageVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/org")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "组织机构管理")
public class OrgController {

    private final SysDeptService deptService;

    @GetMapping("/list")
    @ApiOperation(value = "获取组织机构列表", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页显示的条数", required = true),
            @ApiImplicitParam(name = "deptName", value = "组织机构名称"),
    })
    public R list(@ApiIgnore SysDept sysDept, PageVo pageVo) {
        return R.ok(deptService.selectDeptList(new Page<>(pageVo.getCurrent(), pageVo.getPageSize()), sysDept));
    }

    @GetMapping("/listAll")
    @ApiOperation(value = "获取所有组织机构列表", httpMethod = "POST")
    public R listAll() {
        return R.ok(deptService.list());
    }

    @GetMapping("/tree")
    @ApiOperation(value = "获取所有组织机构树结构", httpMethod = "POST")
    public R tree() {
        return R.ok(deptService.getTree());
    }
}
